load("//bazel:mongo_src_rules.bzl", "mongo_cc_benchmark", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

mongo_cc_benchmark(
    name = "sbe_builder_bm",
    srcs = [
        "sbe_builder_bm.cpp",
    ],
    tags = ["query_bm"],
    deps = [
        "//src/mongo/db/query:query_fcv_environment_for_test",
        "//src/mongo/db/query:query_test_service_context",
        "//src/mongo/db/shard_role/shard_catalog:catalog_test_fixture",
    ],
)

mongo_cc_library(
    name = "query_sbe_abt",
    srcs = [
        "abt_lower.cpp",
    ],
    deps = [
        "//src/mongo/db/exec/sbe:query_sbe_stages",
        "//src/mongo/db/query/stage_builder/sbe/abt:abt_base",
    ],
)

mongo_cc_unit_test(
    name = "abt_lower_test",
    srcs = [
        "//src/mongo/db/query/stage_builder/sbe/tests:abt_lower_test.cpp",
    ],
    data = ["//src/mongo/db/test_output/query/stage_builder/sbe/a_b_t_plan_generation:test_data"],
    tags = ["mongo_unittest_eighth_group"],
    deps = [
        ":query_sbe_abt",
        "//src/mongo/db/exec/sbe:query_sbe",
    ],
)

mongo_cc_unit_test(
    name = "sbe_abt_test",
    srcs = [
        "//src/mongo/db/query/stage_builder/sbe/tests:sbe_abt_test.cpp",
    ],
    tags = ["mongo_unittest_eighth_group"],
    deps = [
        ":query_sbe_abt",
        "//src/mongo/db/exec/sbe:sbe_unittest_base",
        "//src/mongo/db/query:query_test_service_context",
        "//src/mongo/db/query/collation:collator_interface_mock",
    ],
)

# Lightweight test utils.
mongo_cc_library(
    name = "abt_unit_test_utils",
    srcs = [
        "//src/mongo/db/query/stage_builder/sbe/tests:abt_unit_test_utils.cpp",
    ],
    deps = [
        "//src/mongo/bson/dotted_path:dotted_path_support",
        "//src/mongo/db/query/stage_builder/sbe/abt:abt_base",
        "//src/mongo/unittest",
    ],
)

mongo_cc_unit_test(
    name = "abt_unit_test_infra_test",
    srcs = [
        "//src/mongo/db/query/stage_builder/sbe/tests:abt_unit_test_infra_test.cpp",
    ],
    tags = ["mongo_unittest_first_group"],
    deps = [
        ":abt_unit_test_utils",
        "//src/mongo/db/exec/sbe:query_sbe",  # needed to register extended type destruction for MakeObjSpec :(
    ],
)

mongo_cc_benchmark(
    name = "abt_lower_bm",
    srcs = [
        "//src/mongo/db/query/stage_builder/sbe/tests:abt_lower_bm.cpp",
    ],
    deps = [
        ":query_sbe_abt",
        "//src/mongo/db/exec/sbe:query_sbe",
    ],
)

mongo_cc_library(
    name = "stage_builder",
    srcs = [
        "analysis.cpp",
        "builder.cpp",
        "builder_data.cpp",
        "builder_state.cpp",
        "expression_const_eval.cpp",
        "gen_abt_helpers.cpp",
        "gen_accumulator.cpp",
        "gen_coll_scan.cpp",
        "gen_expression.cpp",
        "gen_extract_field_paths.cpp",
        "gen_filter.cpp",
        "gen_group.cpp",
        "gen_helpers.cpp",
        "gen_index_scan.cpp",
        "gen_lookup.cpp",
        "gen_projection.cpp",
        "gen_ts.cpp",
        "gen_window_function.cpp",
        "sbexpr.cpp",
        "sbexpr_helpers.cpp",
        "type_checker.cpp",
        "type_signature.cpp",
        "value_lifetime.cpp",
        "vectorizer.cpp",
        "//src/mongo/db/exec:trial_period_utils.cpp",
        "//src/mongo/db/query:bind_input_params.cpp",
        "//src/mongo/db/query:shard_filterer_factory_impl.cpp",
    ],
    deps = [
        "query_sbe_abt",
        "//src/mongo:base",
        "//src/mongo/bson/column",
        "//src/mongo/db:common",
        "//src/mongo/db:query_expressions",
        "//src/mongo/db:sbe_values",
        "//src/mongo/db:service_context",
        "//src/mongo/db:shard_filterer",
        "//src/mongo/db/commands/server_status:server_status_core",
        "//src/mongo/db/exec:docval_to_sbeval",
        "//src/mongo/db/exec:js_function",
        "//src/mongo/db/exec/document_value",
        "//src/mongo/db/exec/sbe:query_sbe",
        "//src/mongo/db/exec/sbe:query_sbe_makeobj_spec",
        "//src/mongo/db/exec/sbe:query_sbe_plan_stats",
        "//src/mongo/db/exec/sbe:query_sbe_stages",
        "//src/mongo/db/exec/sbe:query_sbe_storage",
        "//src/mongo/db/fts:base_fts",
        "//src/mongo/db/fts:fts_query_noop",
        "//src/mongo/db/index:index_access_method",
        "//src/mongo/db/index:preallocated_container_pool",
        "//src/mongo/db/matcher:expressions_mongod_only",
        "//src/mongo/db/pipeline",
        "//src/mongo/db/pipeline:accumulator",
        "//src/mongo/db/pipeline:field_path",
        "//src/mongo/db/pipeline/process_interface:mongo_process_interface",
        "//src/mongo/db/query:canonical_query_base",
        "//src/mongo/db/query:plan_yield_policy_sbe",
        "//src/mongo/db/query:query_knob_configuration",
        "//src/mongo/db/query:query_planner",
        "//src/mongo/db/query/algebra",
        "//src/mongo/db/query/collation:collator_interface",
        "//src/mongo/db/query/compiler/dependency_analysis:dependencies",
        "//src/mongo/db/query/compiler/logical_model/projection:projection_ast",
        "//src/mongo/db/query/compiler/logical_model/sort_pattern",
        "//src/mongo/db/query/compiler/metadata:query_metadata",
        "//src/mongo/db/query/compiler/optimizer/index_bounds_builder",
        "//src/mongo/db/query/compiler/physical_model/index_bounds",
        "//src/mongo/db/query/datetime:date_time_support",
        "//src/mongo/db/query/plan_cache:query_plan_cache",
        "//src/mongo/db/query/search:mongot_cursor",
        "//src/mongo/db/query/stage_builder/sbe/abt:abt_base",
        "//src/mongo/db/query/stage_builder/sbe/abt/syntax:syntax_expr",
        "//src/mongo/db/query/util:field_set",
        "//src/mongo/db/repl:optime",
        "//src/mongo/db/shard_role/shard_catalog:collection_options",
        "//src/mongo/db/shard_role/shard_catalog:index_catalog",
        "//src/mongo/db/stats:counters",
        "//src/mongo/db/storage:feature_document_util",
        "//src/mongo/db/storage:index_entry_comparison",
        "//src/mongo/db/storage:record_store_base",
        "//src/mongo/db/storage:recovery_unit_base",
        "//src/mongo/db/storage/key_string",
        "//src/mongo/db/timeseries:bucket_compression",
        "//src/mongo/s:sharding_helpers",
        "//src/mongo/stdx",
        "//src/mongo/util:string_listset",
    ],
)
